<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>请求接口</button>
    <div id="result"></div>
    <script>
        const btn = document.querySelector('button')
        const result = document.querySelector('#result')
        btn.addEventListener('click', () => {
            const evtSource = new EventSource('http://localhost:3000/api/sendMsg?msg=123')
            evtSource.onmessage = (e) => {
                console.log("message：",e.data)
                if(e.data == "end"){
                    evtSource.close()
                }
                result.innerHTML += e.data
            }
        })
    </script>
</body>
</html>